package ModelLayer;
import java.util.ArrayList;


/**
 * Write a description of class dvdContainer here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class DvdContainer
{
    // instance variables - replace the example below with your own
    private ArrayList<DVD> dvds;
    Copy copy;

    /**
     * Constructor for objects of class dvdContainer
     */
    public DvdContainer()
    {
        // initialise instance variables
        dvds = new ArrayList<DVD>();
    }
    public void addDVD(DVD dvd)
    {
        dvds.add(dvd);
    }
    public void createCopy(int idOfDvd, int serialNumberOfCopy,String  purchaseDateOfCopy, double purchasePriceOfCopy)
    {
        DVD dvd = findDVD(idOfDvd);
        copy = new Copy(serialNumberOfCopy, purchaseDateOfCopy, purchasePriceOfCopy);
        dvd.addCopy(copy);

}
public DVD findDVD(int id)
{
        DVD dvd = null;
        boolean found = false;
        int index = 0;
        while(index < dvds.size() && !found)
        {
            dvd = dvds.get(index);
            if(dvd.getId() == id)
            {
                found = true;
            }
            else{
                index++;
            }
        }//end while
        if(found){
             return dvds.get(index);
        }
        else{
            return null;
        }
    }
    public void removeDVD(int id )
    {
        DVD dvd = findDVD(id);
        dvds.remove(dvd);
    }
public void updateDVD(int id, String title, String author, String publicationDate)
{
    DVD dvd = findDVD(id);
    dvd.setTitle(title);
    dvd.setAuthor(author);
    dvd.setPublicationDate(publicationDate);
}
public void makedvdList()
{
    
        for(DVD dvd : dvds) 
        {
            System.out.println(dvd.getTitle());
            dvd.makeAListOfCopies();
        }
        
}
public int showDVDListSize()
{
    return dvds.size();
}
}

